# -*- coding: utf-8 -*-
from pymysql.pymysql import DB
import MySQLdb
import logging
import re
import json
from common.service import BasicInterface
import requests
from case_util.interface_test import md5

# isok=DB('db0').Table('common_project').Insert({'name': '项目三', 'description': '哈安抚哈哈哈撒地方哈哈哈', 'product_id': 2})
# p = DB('db0').Select('*').From('common_product').Where('name=?',['产品一']).GetAll()
# p = DB('db0').Select('j.name,d.name').From('common_product d').Join('common_project j','d.id=j.product_id ').GetAll()
# p = DB('db0').Select('id').From('common_project').Where('product_id=? and name=?', [2, '项目二']).GetAll()
# print p
# p = DB('db0').Select('id').From('common_project').Where('product_id=?', [2]).GetAll()
# p = DB('db0').Select('*').From('common_project').Where('product_id=?', [2]).GetAll()
# p=DB('db0').Select('count(id) counts').From('project_interface_ref').GetAll()
# isok = DB('db0').Table('project_interface_ref').Where('project_id=? and api_id=?', [22, 2]).Delete()
# s = "DB('db0').Select('db_config').From('envir_config').Where('id=?', [7]).GetAll()"
# p=eval(s)
# print s
# print p[0]['db_config']
# print p[0]['db_config'].replace('’', "'").replace('，', ',').replace('：',":").split(',')
# print len(p)
# try:
#     conn = MySQLdb.Connect(host='localhost', port=306, user='rot', passwd='adminadmin', db='qadb')
#     print conn
# except MySQLdb.Error, e:
#     print e[1]
# name = ''
# uri = 'uri'
# product_id = 'product_id'
# flag = False
#
# # s =" DB('db0').Select('uri,name,description').From('api').Where('product_id=? and uri=? and name=?', [product_id, uri, name]).GetAll()"
# colnum = ''
# args = []
# if name:
#     colnum = colnum + name + '=?'
#     args.append(name)
#     flag = True
# if uri and flag:
#     colnum = colnum + ' and ' + uri + '=?'
#     args.append(uri)
#     flag = True
# elif uri:
#     colnum = colnum + uri+'=?'
#     args.append(uri)
#     flag = True
# if product_id and flag:
#     colnum = colnum + ' and ' + product_id + '=?'
#     args.append(product_id)
#     flag = True
# elif product_id:
#     colnum = colnum + product_id + '=?'
#     args.append(product_id)
#     flag = True
# if not flag:
#     s = " DB('db0').Select('uri,name,description').From('api').GetAll()"
# else:
#     s = " DB('db0').Select('uri,name,description').From('api').Where(%s, %s).GetAll()" % (
#     colnum, str(args).replace("'", ''))
# print s
# p = DB('db0').Select(
#     'a.name,a.uri,a.description api_desc,g.args_name,g.data_type,g.check_type,g.check_value,g.note, p.field,p.data_type, p.description response_desc,c.code,c.description code_desc').From(
#     'api a').Join('api_args g', 'a.id=g.api_id').Join('api_response p', 'a.id=p.api_id').Join('api_response_codes c',
#                                                                                               'a.id=c.api_id').Where('a.id=?',[1]).GetAll()
# print p[0]['api_desc']
# for i in json.loads(BasicInterface().get_env_configs())['data']:
#     print str(i['name'])+'--------'+str(i['product_name'])
# print DB('db0').Table('checks').Insert(
#             {'step_id': 1, 'check_type':'DB_DAT', 'query_sql': 'DASF', 'check_rule': 'DASFA'})
# DB('db0').Table('steps').Insert({'case_id':1})
